package com.earthchen.gps.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 时间工具类
 *
 * @author: EarthChen
 * @date: 2018/04/28
 */
public class DateTimeUtil {

    /**
     * 根据日期和时间字符串构造时间对象
     *
     * @param dateString
     * @param timeString
     * @return
     */
    public static Date getDateFromDateStringAndTimeString(String dateString, String timeString) {
        String day = dateString.substring(0, 2);
        String month = dateString.substring(2, 4);
        String year = dateString.substring(4, 6);

        String hour = timeString.substring(0, 2);
        String minute = timeString.substring(2, 4);
        String second = timeString.substring(4, 6);

        String datetimeStr = year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;

        SimpleDateFormat sDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        try {
            return sDateFormat.parse(datetimeStr);
        } catch (ParseException px) {
            px.printStackTrace();
        }
        return new Date();
    }
}
